package com.flame.shapeville.component.task4;

import javafx.animation.TranslateTransition;
import javafx.scene.Node;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.StackPane;
import javafx.scene.shape.Shape;
import javafx.util.Duration;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;

/**
 * Abstract base class for all shapes used in Task 4.
 * Provides common layout, animation, and structure functionality for shape rendering.
 *
 * @author Flame Dev Team
 * @version 1.0
 * @since 2025-05-15
 */
public abstract class JfShape {

    /**
     * The main pane containing the visual representation of the shape.
     */
    @Getter
    AnchorPane shape = new AnchorPane();

    /**
     * A detailed pane that includes additional explanations and formulas.
     */
    @Getter
    AnchorPane detailedShape = new AnchorPane();

    /**
     * List of components (nodes) that make up the shape for animation purposes.
     */
    List<Node> components = new ArrayList<>();

    /**
     * List of translate transitions for animating each component.
     */
    List<TranslateTransition> tts = new ArrayList<>();

    /**
     * Size of the drawing area.
     */
    int size;

    /**
     * Default constructor.
     * Sets up initial layout sizes and default size value.
     */
    JfShape() {
        shape.setPrefSize(480, 240);
        size = 200;
    }

    /**
     * Initializes translation animations for all components.
     */
    void initTranslate() {
        for (Node component : components) {
            TranslateTransition tt = new TranslateTransition();
            tt.setNode(component);
            tt.setDuration(Duration.seconds(1));
            tt.setFromX((this.shape.getPrefWidth()) / 4);
            tt.setToX(0);
        }
    }

    /**
     * Abstract method to initialize detailed view with extra explanation and formula.
     */
    abstract void initDetailed();

    /**
     * Plays all translation animations.
     */
    public void translateAnimation() {
        tts.forEach(TranslateTransition::play);
    }
}
